/**
 * Created by WangGuoyan on 2017/2/15.
 */

var ibcpFlowCheck = {
    //检查流程图中错误节点
    errorCheck : function(){
        var flowCheck = true;
        var numCheck = [];
        for(var i in objs){
            //判断项公式非空检查
            if(objs[i].objType == "Gate"){
                if(!objs[i].formula || objs[i].formula == "null"){
                    this.errorPrompt(objs[i]);
                    flowCheck = false;
                }
            }
            //将number作为数组储存
            if(objs[i].objType == "Task"){
                numCheck.push(objs[i].number);
                numCheck.sort();
            }
        }

        //步骤项number重复检查
        for(var i in numCheck){
            if(numCheck[i] == numCheck[i - 1] || numCheck[i] == numCheck[i + 1]){
                var errors = getObjectByProp('number', numCheck[i]);
                for(var j in errors){
                    this.errorPrompt(errors[j]);
                }
                flowCheck = false;
            }
        }
        return flowCheck;
    },

    //错误节点闪烁提示
    errorPrompt : function(target){
        var timer1 = null;
        var timer2 = null;
        var opacity = 0.1;
        clearInterval(timer1);
        clearTimeout(timer2);
        timer1 = setInterval(function(){
            target.setOpacity(0.1);
            canvas.renderAll();
            timer2 = setTimeout(function(){
                target.setOpacity(1);
                canvas.renderAll();
            },500);
        },1000);
        canvas.on('object:selected',function(e) {
            if(target == getObjectById(ActiveId)){
                clearInterval(timer1);
                clearTimeout(timer2);
            }
        });
    }
};